﻿using System;
using System.IO;

namespace Synology.DS.Common
{
	public static class FileSystemHelpers
	{
		public static void EnsureDirectoryExistance(string directory)
		{
			if (!Directory.Exists(directory))
				Directory.CreateDirectory(directory);
		}

		public static bool IsFileLocked(string fileName)
		{
			if (!File.Exists(fileName))
				throw new FileNotFoundException("", fileName);

			try
			{
				using (File.Open(fileName, FileMode.Open, FileAccess.ReadWrite))
				{
					return false;
				}
			}
			catch (Exception)
			{
				return true;
			}
		}
	}
}
